package com.app.command;

import java.io.BufferedReader;


import com.app.dao.BookDAO;
import com.app.dao.entity.Book;

public class DeleteBookCommand extends Command {

	@Override
	protected CommandResult execute(BufferedReader dataLineReader)
			throws Exception {
		CommandResult result = new CommandResult(CommandResultStatus.SUCCESSFUL);
		BookDAO bookDAO = new BookDAO();
		

		System.out.print(" Enter BookTitle ");

		String bookTitle = dataLineReader.readLine();

		Book book = bookDAO.findBook(bookTitle);
		if (book != null) {
			System.out.println("Book " + book + " Find");
			bookDAO.deleteBook(book);
			System.err.println("Book " + bookTitle + " delete from DB");
		} else {
			System.out.println("Book " + bookTitle + " not find from DB");
		}
		return result;
	}

}
